package books4africa

//THIS IS AN INTEGRATION TEST

import static org.junit.Assert.*
import org.junit.*

class BookTests {
    
    void testPersistence(){
        //create a donor and save it in the database
        Book test = new Book(title: "Title", author: "Author", 
            description: null, edition: null, publishDate: null, isbn: 0, 
            minGrade: 2, maxGrade: 5, category: "Math").save()
        
        
        
        Book retrieved = Book.findByTitle("Title");
        
        println retrieved.title
        
        assertEquals(test, retrieved)
        
    }
    
    void testInventoryList(){
        //create an inventoryList to add to the book's inventory lists
        Book hasIList = new Book(title: "Title", author: "Author", 
            description: null, edition: null, publishDate: null, isbn: 0, 
            minGrade: 2, maxGrade: 5, category: "Math").save()
        
        InventoryList iList = new InventoryList(quantity: 30, donor: new 
            Donor(userID:"hullabaloo@gmail.net", password: "password", 
                listOfCategories: null))
            
        hasIList.addToInventoryLists(iList);
        
        Book foundBook = Book.get(hasIList.id);
        
        assertEquals(foundBook.inventoryLists.size(), 1)
       
    }
    
    void testDonationList(){
        //create an inventoryList to add to the book's inventory lists
        Book hasDList = new Book(title: "Title", author: "Author", 
            description: null, edition: null, publishDate: null, isbn: 0, 
            minGrade: 2, maxGrade: 5, category: "Math").save()
        
        DonationList dList1 = new DonationList(quantity: 30, donor: new 
            Donor(userID:"hullabaloo@gmail.net", password: "password", 
                listOfCategories: null))
        
        DonationList dList2 = new DonationList(quantity: 62, donor: new 
            Donor(userID:"hullabaloo@gmail.net", password: "password", 
                listOfCategories: null))
            
        hasDList.addToDonationLists(dList1);
        hasDList.addToDonationLists(dList2);
        
        Book foundBook = Book.get(hasDList.id);
        
        assertEquals(foundBook.donationLists.size(), 2)
    }
}
